package com.gmall.user.controller;

import com.gmall.model.user.UserAddress;
import com.gmall.user.service.UserAddressService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;
import java.util.List;

@RestController
@RequestMapping("/api/user")
public class UserAddressController {

    @Autowired
    private UserAddressService userAddressService;

    /**
     * 查询用户地址列表
     * api/user/inner/findUserAddressListByUserId/{userId}
     * @param userId
     * @return
     */
    @GetMapping("/findUserAddressListByUserId/{userId}")
    public List<UserAddress> findUserAddressListByUserId(@PathVariable Long userId){
        return this.userAddressService.findUserAddressListByUserId(userId);
    }

    @GetMapping("/findUserAddressList1")
    public List<UserAddress> findUserAddressList1(@RequestHeader Long userId){
        return this.userAddressService.findUserAddressListByUserId(userId);
    }

    @GetMapping("/findUserAddressList2")
    public List<UserAddress> findUserAddressList2(HttpServletRequest request){
        Long userId = Long.parseLong(request.getHeader("userId"));
        return this.userAddressService.findUserAddressListByUserId(userId);
    }

}
